/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: JdbcTypeFormat.java   2020-10-10 21-52-18
 * Author: Evan
 */
package cn.datacare.orm.engine.format;

import cn.datacare.orm.type.JavaType;
import org.beetl.core.Format;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-10-10 21-52-18
 * @since V1.0
 */
public class JdbcTypeFormat implements Format {

    /**
     * 减号{@value}
     */
    public static final char MINUS = '-';

    /**
     * @param data    格式化对象
     * @param pattern ，模式，格式换函数需要考虑到pattern为null的情况
     * @return Object
     */
    @Override
    public Object format(Object data, String pattern) {
        char cs = pattern.charAt(0);
        if (cs == MINUS || Character.isDigit(cs)) {
            return Integer.parseInt(pattern);
        }
        return JavaType.jdbcTypeNames.get(pattern.toLowerCase());
    }
}
